
// jsx 老的转换成 React.createElement

const babel = require("@babel/core");
const sourceCode = `<h1 id="title" key="title" ref="title">hello</h1>`;
const result = babel.transform(sourceCode, {
    plugins: [['@babel/plugin-transform-react-jsx',{runtime:'classic'}]]
});
console.log(result.code);
/*
React.createElement("h1", {
    id: "title",
    key: "title",
    ref: "title"
}, "hello");
*/

// jsx 新的转换成 React.createElement
const babel = require("@babel/core");
const sourceCode = `<h1 id="title" key="title" ref="title">hello</h1>`;
const result = babel.transform(sourceCode, {
    plugins: [['@babel/plugin-transform-react-jsx',{runtime:'automatic'}]]
});
console.log(result.code);
/**
import { jsx as _jsx } from "react/jsx-runtime";

_jsx("h1", {
    id: "title",
    ref: "title",
    children: "hello"
}, "title");
 */

// 可以配置 cross-env DISABLE_NEW_JSX_TRANSFORM=true 禁用新的转换器